import store from '@/store'
import {
	jump
} from "./tool"
import BasicConfig from "@/utils/config"
const Whitelist = ["/pages/index/index", "/pages/my/my"]
/**
 * @description 跳转页面前的用户登录验证
 * @param {String} to : 要跳转的页面
 * @param {String} mode : 跳转方式 默认:'navigateTo'
 * @param {Boolean} login : 是否验证登录
 * @param {Boolean} open : 打开方式 JumpTypeEnum
 * @param {Object} query : 参数
 */
export const jumpPage = (params) => {
	params = params || {};
	const isLogin = store.state.login.isLogin; // 用户是否登录
	const isVerLogin = params.login ?? true;
	const to = typeof params === "string" ? params : params.to;
	const isPerfect = store.state.user.perfect;
	if (!isPerfect && !Whitelist.includes(to)) {
		uni.showModal({
			content: "请完善资料后再进行操作",
			success(modalRes) {
				if (modalRes.confirm) {
					uni.switchTab({
						url: "/pages/my/my"
					})
				}
			}
		})
		// BasicConfig.toast("请完善资料后再进行操作")
	} else {
		// 登录验证
		if (!isLogin && isVerLogin) {
			jump({
				to: "/pages/auth/index"
			})
		}
		// 跳页
		else jump(params)
	}
}